home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / Basic / Visual Basic.60 / COMMON / TOOLS / VB / OLEMSG / TIMECARD.CLI / CLIENT / REPORT.FRM (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1996-06-15  |  16.4 KB  |  553 lines

  1. VERSION 5.00
  2. Begin VB.Form formReport 
  3.    Caption         =   "Time Report Form"
  4.    ClientHeight    =   5295
  5.    ClientLeft      =   930
  6.    ClientTop       =   2175
  7.    ClientWidth     =   10485
  8.    Height          =   5700
  9.    Left            =   870
  10.    LinkTopic       =   "Form1"
  11.    ScaleHeight     =   5295
  12.    ScaleWidth      =   10485
  13.    Top             =   1830
  14.    Width           =   10605
  15.    Begin VB.TextBox txtTo 
  16.       Height          =   288
  17.       Left            =   1080
  18.       TabIndex        =   25
  19.       Top             =   120
  20.       Width           =   5052
  21.    End
  22.    Begin VB.TextBox txtCell 
  23.       Height          =   288
  24.       Index           =   8
  25.       Left            =   8760
  26.       TabIndex        =   24
  27.       Top             =   2160
  28.       Width           =   972
  29.    End
  30.    Begin VB.TextBox txtCell 
  31.       Height          =   288
  32.       Index           =   7
  33.       Left            =   7680
  34.       TabIndex        =   23
  35.       Top             =   2160
  36.       Width           =   972
  37.    End
  38.    Begin VB.TextBox txtCell 
  39.       Height          =   288
  40.       Index           =   6
  41.       Left            =   6600
  42.       TabIndex        =   22
  43.       Top             =   2160
  44.       Width           =   972
  45.    End
  46.    Begin VB.TextBox txtCell 
  47.       Height          =   288
  48.       Index           =   5
  49.       Left            =   5520
  50.       TabIndex        =   21
  51.       Top             =   2160
  52.       Width           =   972
  53.    End
  54.    Begin VB.TextBox txtCell 
  55.       Height          =   288
  56.       Index           =   4
  57.       Left            =   4440
  58.       TabIndex        =   20
  59.       Top             =   2160
  60.       Width           =   972
  61.    End
  62.    Begin VB.TextBox txtCell 
  63.       Height          =   288
  64.       Index           =   3
  65.       Left            =   3360
  66.       TabIndex        =   19
  67.       Top             =   2160
  68.       Width           =   972
  69.    End
  70.    Begin VB.TextBox txtCell 
  71.       Height          =   288
  72.       Index           =   2
  73.       Left            =   2280
  74.       TabIndex        =   18
  75.       Top             =   2160
  76.       Width           =   972
  77.    End
  78.    Begin VB.TextBox txtCell 
  79.       Height          =   288
  80.       Index           =   1
  81.       Left            =   1200
  82.       TabIndex        =   17
  83.       Top             =   2160
  84.       Width           =   972
  85.    End
  86.    Begin VB.TextBox txtCell 
  87.       Height          =   288
  88.       Index           =   0
  89.       Left            =   120
  90.       TabIndex        =   14
  91.       Top             =   2160
  92.       Width           =   972
  93.    End
  94.    Begin VB.CommandButton btnClear 
  95.       Caption         =   "&Clear All"
  96.       Height          =   372
  97.       Left            =   8400
  98.       TabIndex        =   5
  99.       Top             =   120
  100.       Width           =   852
  101.    End
  102.    Begin VB.CommandButton btnSend 
  103.       Caption         =   "&Send"
  104.       Height          =   372
  105.       Left            =   7080
  106.       TabIndex        =   4
  107.       Top             =   120
  108.       Width           =   972
  109.    End
  110.    Begin VB.TextBox txtPayPeriod 
  111.       Height          =   288
  112.       Left            =   7080
  113.       TabIndex        =   16
  114.       Top             =   960
  115.       Width           =   2172
  116.    End
  117.    Begin VB.TextBox txtName 
  118.       Height          =   288
  119.       Left            =   1080
  120.       TabIndex        =   1
  121.       Top             =   960
  122.       Width           =   4452
  123.    End
  124.    Begin VB.Line Line2 
  125.       X1              =   0
  126.       X2              =   9720
  127.       Y1              =   1560
  128.       Y2              =   1560
  129.    End
  130.    Begin VB.Label Label13 
  131.       Alignment       =   2  'Center
  132.       Caption         =   "Total"
  133.       Height          =   252
  134.       Left            =   8880
  135.       TabIndex        =   15
  136.       Top             =   1800
  137.       Width           =   732
  138.    End
  139.    Begin VB.Label Label12 
  140.       Alignment       =   2  'Center
  141.       Caption         =   "Sat"
  142.       Height          =   252
  143.       Left            =   7800
  144.       TabIndex        =   13
  145.       Top             =   1800
  146.       Width           =   732
  147.    End
  148.    Begin VB.Label Label11 
  149.       Alignment       =   2  'Center
  150.       Caption         =   "Fri"
  151.       Height          =   252
  152.       Left            =   6720
  153.       TabIndex        =   12
  154.       Top             =   1800
  155.       Width           =   732
  156.    End
  157.    Begin VB.Label Label10 
  158.       Alignment       =   2  'Center
  159.       Caption         =   "Thu"
  160.       Height          =   252
  161.       Left            =   5640
  162.       TabIndex        =   11
  163.       Top             =   1800
  164.       Width           =   732
  165.    End
  166.    Begin VB.Label Label9 
  167.       Alignment       =   2  'Center
  168.       Caption         =   "Wed"
  169.       Height          =   252
  170.       Left            =   4560
  171.       TabIndex        =   10
  172.       Top             =   1800
  173.       Width           =   732
  174.    End
  175.    Begin VB.Label Label8 
  176.       Alignment       =   2  'Center
  177.       Caption         =   "Tue"
  178.       Height          =   252
  179.       Left            =   3480
  180.       TabIndex        =   9
  181.       Top             =   1800
  182.       Width           =   732
  183.    End
  184.    Begin VB.Label Label7 
  185.       Alignment       =   2  'Center
  186.       Caption         =   "Mon"
  187.       Height          =   252
  188.       Left            =   2400
  189.       TabIndex        =   8
  190.       Top             =   1800
  191.       Width           =   732
  192.    End
  193.    Begin VB.Label Label6 
  194.       Alignment       =   2  'Center
  195.       Caption         =   "Sun"
  196.       Height          =   252
  197.       Left            =   1320
  198.       TabIndex        =   7
  199.       Top             =   1800
  200.       Width           =   732
  201.    End
  202.    Begin VB.Label lblCategories 
  203.       Alignment       =   2  'Center
  204.       Caption         =   "Categories"
  205.       Height          =   252
  206.       Left            =   240
  207.       TabIndex        =   6
  208.       Top             =   1800
  209.       Width           =   852
  210.    End
  211.    Begin VB.Label Label4 
  212.       Caption         =   "Pay Period"
  213.       Height          =   252
  214.       Left            =   5880
  215.       TabIndex        =   3
  216.       Top             =   960
  217.       Width           =   852
  218.    End
  219.    Begin VB.Label Label2 
  220.       Caption         =   "Name:"
  221.       Height          =   252
  222.       Left            =   120
  223.       TabIndex        =   2
  224.       Top             =   960
  225.       Width           =   492
  226.    End
  227.    Begin VB.Line Line1 
  228.       X1              =   0
  229.       X2              =   9720
  230.       Y1              =   720
  231.       Y2              =   720
  232.    End
  233.    Begin VB.Label Label1 
  234.       Caption         =   "To:"
  235.       Height          =   252
  236.       Left            =   240
  237.       TabIndex        =   0
  238.       Top             =   120
  239.       Width           =   492
  240.    End
  241. Attribute VB_Name = "formReport"
  242. Attribute VB_Base = "0{D624D371-C698-11CF-A520-00A0D1003923}"
  243. Attribute VB_GlobalNameSpace = False
  244. Attribute VB_Creatable = False
  245. Attribute VB_TemplateDerived = False
  246. Attribute VB_PredeclaredId = True
  247. Attribute VB_Exposed = False
  248. Attribute VB_Customizable = False
  249. Const RowSize As Integer = 9
  250. Dim objRequestMsg As Object 'the request message
  251. Dim ReportCategories  As Variant
  252. Dim CatNum As Integer   'number of report categories in ReportCategories
  253. Dim PayPeriod As Date
  254. Dim ReportData() As WeekDataType
  255. Public Sub Init()
  256. 'if there is a request message in the inbox, show the form
  257. If FindRequestMsg Then
  258.     ShowReportForm
  259. End If
  260. End Sub
  261. Function NumFromString(txtstr As String) As Double
  262. If IsNumeric(txtstr) Then
  263.     NumFromString = Val(txtstr)
  264.     NumFromString = 0
  265. End If
  266. End Function
  267. Public Function ShowReportForm() As Boolean
  268. 'if can succesfully extract necessary prop from the
  269. 'request message show the form
  270.  On Error GoTo error_olemsg
  271.     If objRequestMsg Is Nothing Then
  272.         MsgBox "No  active request message"
  273.         ShowReportForm = False
  274.         Exit Function
  275.     End If
  276.     If Not ExtractProps Then
  277.         ShowReportForm = False
  278.         Exit Function
  279.     End If
  280.     formReport.Show 1
  281.        
  282.     ShowReportForm = True
  283.     Exit Function
  284. error_olemsg:
  285.     MsgBox "Error " & Str(Err) & ": " & Error$(Err)
  286.     Resume Next
  287. End Function
  288. Private Function ExtractProps() As Boolean
  289. 'Reads number of report categories, report categiry names
  290. ' and pay period from the reques message
  291. Dim objFields As Object
  292. On Error GoTo error_olemsg
  293. If objRequestMsg Is Nothing Then
  294.     MsgBox "no message"
  295.     ExtractProps = False
  296.     Exit Function
  297. End If
  298. 'get msg's fields collection
  299. Set objFields = objRequestMsg.Fields
  300. If objFields Is Nothing Then
  301.     MsgBox "Error reading request message"
  302.     Exit Function
  303. End If
  304. 'number of categories
  305. CatNum = objFields.Item(NumCatPropName).Value
  306. 'report categories
  307. ReportCategories = objFields.Item(CatPropName).Value
  308. 'pay period
  309. PayPeriod = objFields.Item(PayPeriodPropName)
  310. ExtractProps = True
  311. Exit Function
  312. error_olemsg:
  313.     MsgBox "Error " & Str(Err) & ": " & Error$(Err)
  314.     ExtractProps = False
  315.     Exit Function
  316. End Function
  317. Private Function FindRequestMsg() As Boolean
  318. 'finds request message in the inbox
  319. '(request message has message class RequestMsgType)
  320. 'RequestMsgType is a const defined in tmcrdcmn.bas
  321. 'This functon doesn't deal very well with the situation when
  322. 'there are more than one request message in the inbox,
  323. 'It just gets the one returned by Inbox.Messges.GetFirst(RequestMsgType)
  324. 'This can be changed to showing the listbox with all the request messages
  325. 'and letting user choose the one he/she wants to user
  326. On Error GoTo error_olemsg
  327. Dim objInbox As Object
  328. Dim objMessages As Object
  329. Dim objMessage As Object
  330.     If objSession Is Nothing Then
  331.         MsgBox "Not logged on"
  332.         FindRequestMsg = False
  333.         Exit Function
  334.     End If
  335.     'get the inbox
  336.     Set objInbox = objSession.Inbox
  337.     If objInbox Is Nothing Then
  338.         MsgBox "Failed to open Inbox"
  339.         FindRequestMsg = False
  340.         Exit Function
  341.     End If
  342.     'get the inbox's message collection
  343.     Set objMessages = objInbox.Messages
  344.     If objMessages Is Nothing Then
  345.         MsgBox "Failed to open folder's Messages collection"
  346.         FindRequestMsg = False
  347.         Exit Function
  348.     End If
  349.     Set objMessage = objMessages.GetFirst(RequestMsgType)
  350.     If objMessage Is Nothing Then
  351.         MsgBox "no request msg found"
  352.         FindRequestMsg = False
  353.         Exit Function
  354.     End If
  355.     Set objRequestMsg = objMessage
  356.         
  357.     FindRequestMsg = True
  358.     Exit Function
  359. error_olemsg:
  360.     MsgBox "Error " & Str(Err) & ": " & Error$(Err)
  361.     Resume Next
  362. End Function
  363. Private Sub ShowGrid()
  364. 'displays the a appropriate number of edit boxes
  365. 'on the form
  366. Const initX As Integer = 120
  367. Const initY As Integer = 2160
  368. Const deltaX As Integer = 1080
  369. Const deltaY As Integer = 600
  370. Dim row As Integer
  371. Dim col As Integer
  372. Dim ind As Integer
  373. For row = 1 To CatNum - 1
  374.     For col = 1 To RowSize
  375.         ind = row * RowSize + col - 1
  376.         Load txtCell(ind)
  377.         txtCell(ind).Top = initY + row * deltaY
  378.         txtCell(ind).Left = initX + (col - 1) * deltaX
  379.         txtCell(ind).Visible = True
  380.     Next col
  381. Next row
  382. For row = 0 To CatNum - 1
  383.     txtCell(row * RowSize).Text = ReportCategories(row)
  384.     txtCell(row * RowSize).Enabled = False
  385.     txtCell((row + 1) * RowSize - 1).Enabled = False
  386. Next row
  387. End Sub
  388. Function SumUpRow(RowNum As Integer) As Double
  389. Dim ind As Integer
  390. Dim total As Double
  391. total = 0
  392. For ind = 1 To RowSize - 2 Step 1
  393.     total = total + NumFromString(txtCell.Item((RowNum - 1) * RowSize + ind).Text)
  394. Next ind
  395. SumUpRow = total
  396. End Function
  397. Private Sub btnClear_Click()
  398. Dim row As Integer
  399. Dim col As Integer
  400. Dim ind As Integer
  401. For row = 0 To CatNum - 1 Step 1
  402.     For col = 2 To RowSize
  403.         ind = row * RowSize + col - 1
  404.         txtCell(ind).Text = ""
  405.     Next col
  406. Next row
  407. End Sub
  408. Private Sub btnSend_Click()
  409. 'generates and sends a report message
  410. On Error GoTo error_olemsg
  411. Dim objReportMsg As Object
  412. Dim obj As Object
  413. Dim objR As Object
  414. Dim prop As Object
  415. Dim objFields As Object
  416. Dim PropName As String
  417. Dim row As Integer
  418. Dim col As Integer
  419. Dim ind As Integer
  420. MousePointer = WaitCursor
  421. ReDim ReportData(CatNum)
  422. Dim dbgstr As String
  423. dbgstr = ""
  424. 'get the data
  425. For row = 0 To CatNum - 1 Step 1
  426.     For col = 2 To RowSize - 1 'don't need total
  427.         ind = row * RowSize + col - 1
  428.         ReportData(row).Day(col - 2) = NumFromString(txtCell(ind).Text)
  429.         dbgstr = dbgstr & ReportData(row).Day(col - 2) & " "
  430.     Next col
  431.     Debug.Print dbgstr
  432.     dbgstr = ""
  433. Next row
  434. If objSession Is Nothing Then
  435.     MsgBox "Not logged on"
  436.     Exit Sub
  437. End If
  438. 'create a new message in the outbox
  439. Set objReportMsg = objSession.Outbox.Messages.Add
  440. If objReportMsg Is Nothing Then
  441.     MsgBox "Can't add a prop"
  442.     Exit Sub
  443. End If
  444. 'set the message class
  445. objReportMsg.Type = ReportMsgType
  446. 'address the message to the sender of the request message
  447. Set objR = objReportMsg.Recipients.Add(EntryId:=objRequestMsg.Sender.ID, _
  448.                                         Name:=objRequestMsg.Sender.Name)
  449. If objR Is Nothing Then
  450.     MsgBox "Can't set recipient"
  451.     Exit Sub
  452. End If
  453. 'get msg field collection
  454. Set objFields = objReportMsg.Fields
  455. If objFields Is Nothing Then
  456.     MsgBox "Internal error. (can't access msg's field collecton)"
  457.     Exit Sub
  458. End If
  459. 'report data is transmitted in named properties.
  460. 'name for the property containing data for the i-th category is "i"
  461. 'i = 1, 2, ..., NumberOfCategories
  462. For row = 1 To CatNum Step 1
  463.     PropName = RepDataPropPrefix & Str(row)
  464.     'we can't write:
  465.     'Set obj = objFields.Add(Name:=PropName, _
  466.                              Class:=vbDouble + vbArray, _
  467.                              Value:=ReportData(row - 1.Day)
  468.     'because of the way VB passes array parameters
  469.     'so we first add a property and then set its value
  470.     Set obj = objFields.Add(Name:=PropName, _
  471.                                     Class:=vbDouble + vbArray)
  472.     If obj Is Nothing Then
  473.         MsgBox "Can't add a prop"
  474.         Exit Sub
  475.     End If
  476.     obj.Value = ReportData(row - 1).Day
  477. Next row
  478. Set obj = objFields.Add(Name:=CatPropName, _
  479.                                     Class:=vbString + vbArray)
  480. If obj Is Nothing Then
  481.         MsgBox "Can't add a prop"
  482.         Exit Sub
  483.     End If
  484. obj.Value = ReportCategories
  485. Set obj = objFields.Add(Name:=NumCatPropName, _
  486.             Class:=vbInteger, _
  487.             Value:=CatNum)
  488. If obj Is Nothing Then
  489.         MsgBox "Can't add a prop"
  490.         Exit Sub
  491. End If
  492. Set prop = objFields.Add(Name:=PayPeriodPropName, _
  493.             Class:=vbDate, _
  494.             Value:=PayPeriod)
  495. If prop Is Nothing Then
  496.         MsgBox "Can't add a prop"
  497.         Exit Sub
  498. End If
  499. '$for testing only, later this field (txtName)
  500. 'will be read-only
  501. 'Set obj = objFields.Add(Name:=NamePropName, _
  502.             Class:=vbString, _
  503.             Value:=txtName.Text)
  504. 'If obj Is Nothing Then
  505. '        MsgBox "Can't add a prop"
  506. '        Exit Sub
  507. 'End If
  508. objReportMsg.Send showDialog:=False
  509. MousePointer = DefaultCursor
  510. Unload Me
  511. Exit Sub
  512. error_olemsg:
  513.     MsgBox "Error " & Str(Err) & ": " & Error$(Err)
  514.     Resume Next
  515. End Sub
  516. Private Sub Categories_Click()
  517. End Sub
  518. Private Sub Form_Load()
  519.     txtTo.Text = objRequestMsg.Sender.Name
  520.     txtTo.Enabled = False
  521.     txtName.Text = objSession.CurrentUser.Name
  522.     txtName.Enabled = False
  523.     txtPayPeriod.Text = PayPeriod
  524.     txtPayPeriod.Enabled = False
  525.     ShowGrid
  526. End Sub
  527. Private Sub Form_Unload(Cancel As Integer)
  528.     CatNum = 0
  529.     Set objRequestMsg = Nothing
  530. End Sub
  531. Private Sub txtCell_LostFocus(Index As Integer)
  532. 'do some validation
  533. Dim indTot As Integer
  534.     If (Index Mod RowSize = 0) Or ((Index + 1) Mod RowSize = 0) Then
  535.         Debug.Print "LostFocus from a disable control"
  536.         Exit Sub
  537.     End If
  538.     If txtCell.Item(Index).Text = "" Then
  539.         Exit Sub
  540.     End If
  541.     If IsNumeric(txtCell.Item(Index).Text) And _
  542.         Val(txtCell.Item(Index).Text) >= 0 And _
  543.         Val(txtCell.Item(Index).Text) <= 24 Then
  544.         
  545.         indTot = (Index \ RowSize) * RowSize + RowSize - 1
  546.         txtCell.Item(indTot).Text = SumUpRow(Index \ RowSize + 1)
  547.     Else
  548.         MsgBox "Has to be number of hours." + Chr(13) + _
  549.                 "(Can not be greater than 24)"
  550.         txtCell(Index).SetFocus
  551.     End If
  552. End Sub
  553.